package com.smartrm.trade.adapter.api;

import com.smartrm.globalinfrcore.api.CommonResponse;
import com.smartrm.trade.application.AppTradeService;
import com.smartrm.trade.application.dto.SelectCommodityCmdDto;
import com.smartrm.trade.application.dto.VendingMachineCommodityListDto;
import com.smartrm.trade.domain.SlotVendingMachineState;
import com.smartrm.trade.domain.valueobject.PaymentQrCodeVOJ;
import com.smartrm.trade.domain.valueobject.VendingMachineCommodityListVOJ;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 * @program: common-starters
 * @description: 交易接口
 * @author: houhong
 * @create: 2023-01-10 17:02
 */
@RestController
@RequestMapping("/trade")
public class TradeController {

    @Autowired
    private AppTradeService tradeService;

    /*
     * 顾客查看货道售卖机
     */
    @GetMapping("/slot/listCommodity/{machineId}")
    public CommonResponse<VendingMachineCommodityListDto> listCommodity(@PathVariable("machineId")
                                                                                Long machineId) throws Exception {

        VendingMachineCommodityListDto res = tradeService.vendingMachineShowCommodityList(machineId);
        return CommonResponse.success(res);

    }

    /*
     * 孤苦通过货道售卖机选择商品，并且展示支付二维码
     */
    @PostMapping("/slot/select")
    public CommonResponse<PaymentQrCodeVOJ> selectCommodity(@RequestBody SelectCommodityCmdDto
                                                                    selectCommodityCmdDto) throws Exception {

        PaymentQrCodeVOJ paymentQrCodeVOJ = tradeService.selectCommodity(selectCommodityCmdDto);
        return CommonResponse.success(paymentQrCodeVOJ);
    }
}